#定义一个学生Student类
""""""
"""
class Student():
    def __init__(self,name,age,score):
        self.name = name
        self.age = age
        self.score = score
    def get_name(self):
        return str(self.name)
    def get_age(self):
        return int(self.age)
    def get_course(self):
        return int(max(self.score))
    def f(self):
        with open("xuesheng.txt","a") as f:
           f.write(f'姓名: {self.name}, 年龄: {self.age}, 最高成绩: {self.get_course()}\n')
    def huoqu(self):
        with open("xuesheng.txt","r") as f:
            f.read(f'姓名: {self.name}, 年龄: {self.age}, 最高成绩: {self.get_course()}\n')

t1 = Student('a',29,[99,100,85])
print(t1.get_name())
print(t1.get_age())
print(t1.get_course())
print(t1.f())
print(t1.huoqu())
"""
#定义一个字典类：dictclass
"""
class Dictclass:
    def __init__(self,dict):
        self.dict = dict
    def shanchu(self,key):
       # for i in self.dict:
           # if i == key:
           #     del self.dict[i]
        
        if key in self.key:
            del self.dict[key]
        else:
            print("删除失败")
       
    def chazhao(self,key):
        for i in self.dict:
            if i == key:
                return self.dict[i]
            else:
                print("not found")
    def liebiao(self):
        return list(self.dict)
    def hebin(self, otherdict):
        self.dict.update(otherdict)
        return list(self.dict.values)
"""
#定义一个列表的操作类
"""
class Listinfo():
    def __init__(self,list1):
        self.list1 = list1
    def add_key(self,keyname):
        return self.list1.append(keyname)
    def get_key(self,num):
        return self.list1[num]
    def update_list(self,list2):
        if isinstance(list2,list):
            self.list1 += list2

    def del_key(self):
        if len(self.list1) > 0:
             return self.list1.pop()
"""
#做一个学生点名系统

import random
class Student():
    def __init__(self,name,age,address,phone):
        self.students = {}
        self.name = name
        self.age = age
        self.address = address
        self.phone = phone
    def add(self,name,age,address,phone):
        studentss = {"name":name, "age": age, "address": address, "phone": phone}
        self.students.update(studentss)
        print(f"{name} 存入成功")
        print(self.students)
    def update(self,field, value):
        if self.name in self.students:
            if field in self.students[self.name]:
                self.students[self.name][field] = value
                print(f"{self.name} 的 {field} 更新成功")
    def shanchu(self):
        if self.name in self.students:
            del self.students[self.name]
            print(f"{self.name} 删除成功")
        else:
            print("删除失败")

    def zhanshi(self):
        if self.students:
            for name in self.students.items():
                print(f"{name}: 年龄 {'age'}，家庭地址 {'address'}，手机号 {'phone'}")
    def chouqu(self):
        xingming = random.choice(self.students[self.name])
        print(f"{self.name}到！")
stu = Student("a",5,"4",12)
stu.add("x",6,"a",45)
stu.add("s",4,"l",0)
#点餐管理系统
"""
class Restaurant():
    def __init__(self,name):
        self.name = name
        self.cuisines = []
    def add_cuisine(self,new_cuisine):
        self.cuisines.append(new_cuisine)
    def del_cuisine(self,shanchu):
        del self.cuisines[shanchu]
    def update(self,old_name):
        if self.cuisines[old_name] in self.cuisines:
            new_name = input("输入新菜品：")
            self.cuisines[old_name] = self.cuisines[new_name]
"""
#定义一个桌子类（Desk），包含长（length）、宽（width）、高（height）属性
"""
class Desk:
    def __init__(self,length,width,height):
        self.length = length
        self.width = width
        self.height = height
    def showlinfo(self):
        print(f"桌子长为{self.length},宽为{self.width},高为{self.height}")
"""
#定义一个用户类(User),用户名(username)和密码(password)是这个类的属性。
"""
class User:
    username = 'admin'
    password = '123456'
"""
#定义一个计算器类，有加减乘除四个方法
"""
class Calculator:
    def __init__(self,shuru):
        self.jieguo = 0
        self.shuru = shuru
    def jia(self):
        self.jieguo += self.shuru
        return self.jieguo
    def jian(self):
        self.jieguo -= self.shuru
        return self.jieguo
    def cheng(self):
        self.jieguo *= self.shuru
        return self.jieguo
    def chu(self):
        self.jieguo /= self.shuru
        return self.jieguo
"""
#创建一个名为Person的类
"""
class Person:
    def __init__(self,name,age):
      self.name =name
      self.age = age
    def greet(self):
        print(f"{self.age}岁的{self.name}，你好")
"""
#定义一个图书管理系统类

"""
class Library():
    def __init__(self,book,zuozhe):
       
        self.books = []
        self.book = book
        self.zuozhe = zuozhe
    def add_book(self,book_name,zuozhe,riqi):
        self.books.append({book_name:{"作者" : zuozhe}})
        with open("book.txt",'a') as f:
            f.write(f'新增书{book_name}，作者是{zuozhe},日期是{riqi}')
    def update(self,book_name):
        new_book = input("输入新书名：")
        new_zuozhe = input("输入新的作者：")
        new_time = input("输入新的时间")
        if book_name in self.books:
            self.books.remove(book_name)
            self.books.append({new_book: {"作者": new_zuozhe, "日期": new_time}})
    def del_book(self,book_name):
        if book_name in self.books:
            self.books.remove(book_name)
    def chaxu(self,bookname,zuozhe,shijian):
        if bookname in self.books:
            if zuozhe in self.books:
                if shijian in self.books:
                    return bookname
                    return zuozhe
                    return shijain
"""
#创建一个名为"Car"的类
"""
class Car:
    pinpai = '桑塔纳'
    yanse = '白'
    def start_engine(self):
        print("启动汽车引擎！")
    def stop_engine(self):
        print("关闭汽车引擎！")
"""
#淘宝商家后台，可以上架商品、下架商品
"""
class Taobao:
    def __init__(self,name,sku,price):
        self.names = []
        self.name = name
        self.sku = sku
        self.price = price
    def add_name(self,new_name):
        self.names.append(new_name)
    def update(self,name):
        new_name = input("请输入修改后的商品名称：")
        new_sku = input("输入修改后的sku：")
        new_jiage = input("商品修改后的价格：")
        if name in self.names:
            self.names.remove(name)
            self.names.append({new_name: {"sku": new_sku, "价格": new_jiage}})
        
    def shanchu(self,name):
        if name in self.names:
            self.names.remove(name)
        else:
            print("没有该商品，请确认后重新输入")
"""
#定义一个人类
"""
class Person:
    xiaomei = 45.0
    xiaoming = 75.0
    def __init__(self,xiaomei,xiaoming):
        self.xiaomei = xiaomei
        self.xiaoming = xiaoming
    def run(self,a):
        self.xiaomei -= 0.5*a
        self.xiaoming -= 0.5*a
    def eat(self,a):
        self.xiaomei  += 1*a
        self.xiaoming += 1*a
"""
#士兵瑞恩有一把ak47
"""
class AK:
    def __init__(self,zidan):
        self.zidan = zidan
    def kaihou(self):
        if self.zidan != 0:
            self.zidan -= 1
        if self.zidan == 0:
            print("没有子弹了")
            print("发射失败")
    def add_zidan(self):
        self.zidan += 1
"""







